package com.example.ucs_alg_node_manager.utils;

import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class EmailUtil {
    @Value("${spring.mail.username}")
    private String fromEmail;

    @Resource
    private JavaMailSender javaMailSender;

    @Async
    public  void sendEmail(String toEmail, String account, String password){
        // 验证真的使用我们自己线程
        System.out.println(Thread.currentThread().getName());
        SimpleMailMessage message = new SimpleMailMessage();

        // 设置发件人账号
        message.setFrom(fromEmail);


        // 设置收件人账号
        message.setTo(toEmail);
        // 设置邮件标题
        message.setSubject(account+"用户的密码");
        // 设置邮件内容
        message.setText("重置后的密码为："+password);
        javaMailSender.send(message);
    }

}
